<template>
	<view class="work-container">
		<!-- 轮播图 -->
		<uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
			<swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
				<swiper-item v-for="(item, index) in data" :key="index">
					<view class="swiper-item" @click="clickBannerItem(item)">
						<image :src="item.image" style="width: 710rpx;height: 240rpx;" :draggable="false" />
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>

		<!-- 宫格组件 -->
		<uni-section :title="userInfo.roles[0] + '：' + userInfo.user.nickName" type="line"></uni-section>
		<view class="grid-body">
			<uni-grid :column="3" :showBorder="false">
				<uni-grid-item v-if="hasRouter('招标管理')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/tendereeAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/1.png'" class="iocnimg" mode=""></image>
						<text class="text">招标管理</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-if="hasRouter('订单管理')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/orderAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/1.png'" class="iocnimg" mode=""></image>
						<text class="text">订单管理</text>
					</view>
				</uni-grid-item>
				<uni-grid-item >
					<view class="grid-item-box" @click="gotoPage('/pages/home/purchaseAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/2.png'" class="iocnimg" mode=""></image>
						<text class="text">采购管理</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-if="hasRouter('生产管理')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/productionAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/1.png'" class="iocnimg" mode=""></image>
						<text class="text">生产管理</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-if="hasRouter('库存模块')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/kindsAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/3.png'" class="iocnimg" mode=""></image>
						<text class="text">库存模块</text>
					</view>
				</uni-grid-item>
				<!-- <uni-grid-item v-if="hasRouter('销售管理')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/marketAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/4.png'" class="iocnimg" mode=""></image>
						<text class="text">销售管理</text>
					</view>
				</uni-grid-item> -->
				<!-- <uni-grid-item v-if="hasRouter('开票管理')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/invoiceAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/5.png'" class="iocnimg" mode=""></image>
						<text class="text">开票管理</text>
					</view>
				</uni-grid-item> -->
				<uni-grid-item v-if="hasRouter('报销打款')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/applyAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/6.png'" class="iocnimg" mode=""></image>
						<text class="text">报销打款</text>
					</view>
				</uni-grid-item>
				<!-- <uni-grid-item v-if="hasRouter('客户供应商')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/clientAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/7.png'" class="iocnimg" mode=""></image>
						<text class="text">客户供应商</text>
					</view>
				</uni-grid-item> -->
				<!-- <uni-grid-item v-if="hasRouter('设备车间')">
					<view class="grid-item-box" @click="gotoPage('/pages/home/facilityAdmin/index')">
						<image :src="baseUrl + '/profile/upload/mini/8.png'" class="iocnimg" mode=""></image>
						<text class="text">设备车间</text>
					</view>
				</uni-grid-item> -->
				<uni-grid-item v-if="checkPermi(['develop:WeiwanchengTask:list'])">
					<view class="grid-item-box"
						@click="gotoPage('/pagesA/orderAdmin/productiveTask/index?tableIndex=2')">
						<image :src="baseUrl + '/profile/upload/mini/13.png'"
							style="width: 90rpx;height: 90rpx;margin-bottom: 10rpx;" mode=""></image>
						<text class="text">我的任务</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-if="checkPermi(['develop:GoodsSaledoGongxuUserMoney:list'])">
					<view class="grid-item-box" @click="gotoPage('/pagesA/orderAdmin/reportRecord/index')">
						<image :src="baseUrl + '/profile/upload/mini/14.png'"
							style="width: 90rpx;height: 90rpx;margin-bottom: 10rpx;" mode=""></image>
						<text class="text">报工记录</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-if="checkPermi(['develop:statiStics:export'])">
					<view class="grid-item-box" @click="gotoPage('/pagesB/statistics/index')">
						<image :src="baseUrl + '/profile/upload/mini/3.png'" class="iocnimg" mode=""></image>
						<text class="text">统计</text>
					</view>
				</uni-grid-item>
				<uni-grid-item v-if="checkPermi(['develop:projectCountTj:export'])">
					<view class="grid-item-box" @click="gotoPage('/pagesB/orderStics/index')">
						<image :src="baseUrl + '/profile/upload/mini/3.png'" class="iocnimg" mode=""></image>
						<text class="text">订单数据分析</text>
					</view>
				</uni-grid-item>
				
			</uni-grid>
		</view>
	</view>
</template>

<script>
import * as index from '@/api/index.js'
export default {
	data() {
		return {
			token: '',
			baseUrl: this.$tools.baseURL,
			current: 0,
			swiperDotIndex: 0,
			data: [
				{
					image: this.$tools.baseURL + '/profile/upload/mini/0.png'
				}
			],
			routers: [],
			userInfo: {}
		}
	},
	onLoad() {
		this.getRouters()
		this.getInfo()
	},
	onShow() {
		this.token = uni.getStorageSync('App-Token')
		if (!this.token) {
			this.$tab.reLaunch('/pages/login/index')
		}
		console.log(this.$tools.baseURL)
	},
	methods: {
		getInfo() {
			// 设置用户信息
			this.$store.dispatch('GetInfo').then(res => {
				this.userInfo = res
			})
		},
		hasRouter(name) {
			return this.routers.some(router => router.meta.title === name);
		},
		getRouters() {
			index.getRouters().then(res => {
				this.routers = res.data
				console.log('这是什么玩意', res.data)
			})
		},
		gotoPage(url) {
			uni.navigateTo({
				url: url
			});
		},
		clickBannerItem(item) {
			console.info(item)
		},
		changeSwiper(e) {
			this.current = e.detail.current
		},
		changeGrid(e) {
			console.log(e, '这里是什么啊')
			this.$modal.showToast('模块建设中~')
		}
	}
}
</script>

<style lang="scss">
/* #ifndef APP-NVUE */
page {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background-color: #fff;
	min-height: 100%;
	height: auto;
}

view {
	font-size: 14px;
	line-height: inherit;
}

/* #endif */

.text {
	text-align: center;
	font-size: 26rpx;
	margin-top: 10rpx;
}

.grid-item-box {
	flex: 1;
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 15px 0;

	.iocnimg {
		width: 90rpx;
		height: 90rpx;
		margin-bottom: 10rpx;
	}
}

.uni-margin-wrap {
	width: 690rpx;
	width: 100%;
	;
}

.swiper {
	height: 300rpx;
}

.swiper-box {
	height: 150px;
}

.swiper-item {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	justify-content: center;
	align-items: center;
	color: #fff;
	height: 300rpx;
	line-height: 300rpx;
}

@media screen and (min-width: 500px) {
	.uni-swiper-dot-box {
		width: 400px;
		/* #ifndef APP-NVUE */
		margin: 0 auto;
		/* #endif */
		margin-top: 8px;
	}

	.image {
		width: 100%;
	}
}
</style>